#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>

typedef int ElemType;
typedef struct Node
{
    ElemType data;
    struct Node* next;
}Node, * LinkList;

void Init(Node* head)
{
    ElemType x;
    Node* s, * r;
    r = head;
    int i = 1;
    for (i = 1; i <= 6; i++)
    {
        s = (Node*)malloc(sizeof(Node));
        s->data = i;
        s->next = r->next;
        r->next = s;
        r = r->next;
    }
}
void Output(Node* head)
{
    Node* p;
    p = head->next;
    while (p != head)
    {
        printf("%d ", p->data);
        p = p->next;
    }
    printf("\n\n");
}void Joseph(Node* la)
{
    Node* pre, * p;
    pre = la;
    p = la->next;
    while (p->next != la || pre != la)
    {
        for (int i = 1; i <= 3; i++)
        {
            pre = p;
            p = p->next;
            if (p == la)
            {
                pre = p;
                p = p->next;
            }
        }
        pre->next = p->next;
        free(p);
        p = pre->next;
        Output(la);
    }
}
int main()
{
    Node* la;
    la = (Node*)malloc(sizeof(Node));
    la->next = la;

    Init(la);
    Output(la);

    Joseph(la);
    Output(la);
}